/*
 * StateOT.java
 *
 * $Id: StateOT.java,v 1.1 2009-04-27 06:21:59 juancarlos Exp $
 */
package org.ceteca.explica.core.common;

import java.io.Serializable;

import org.ceteca.explica.core.InterfaceExplica;

/**
 * Store class to hold the data of a province.
 * <br/>
 * Responsibilities:
 * <li>
 * 	<ul> Store of province data for exchanging data among presentation, 
 * business and data access layers. </ul>
 * </li>.
 * <br/>
 * @author Mario García García <mario@ceteca.es>
 * Copyright (c) 2009 Fundación Centro Tecnolóxico da Carne
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * <br/>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * <br/>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
public class StateOT extends BaseVO implements Serializable{
	/**
	 * Internal id of the province.
	 */
	private long idState;
	/**
	 * Name of the province.
	 */
	private String name;
	
	private CountryOT country;
	
	/**
	 * Version of the province used by Hibernate for optimistic concurrency control.
	 */
	private Integer version = new Integer(0);
	private static final long serialVersionUID = 10000002;

	
	
	
	
	
	
	
	public StateOT() {
		super();

	}
	public CountryOT getCountry() {
		return country;
	}
	public void setCountry(CountryOT country) {
		this.country = country;
	}

	public long getIdState() {
		return idState;
	}
	public void setIdState(long idState) {
		this.idState = idState;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * Gets the version of the province used by Hibernate for optimistic concurrency control.
	 * @return Integer, version of the group.
	 */
	public Integer getVersion() {
		return version;
	}
	/**
	 * Sets up the version of the province used by Hibernate for optimistic concurrency control.
	 * @param version Integer, version of the group.
	 */
	public void setVersion(Integer version) {
		this.version = version;
	}
	
	/**
	 * Implementation of the equals method provided by the serializable interface.
	 */
	public boolean equals(Object other) {
		boolean isEqual = false;
        if (this == other) 
        	return true;
        if ( !(other instanceof StateOT) ) 
        	return false;

        final StateOT prov = (StateOT) other;

        if ( prov.getName() == null )
        	isEqual = this.getName() == null;
        else 
        	isEqual = prov.getName().equals( this.getName()); 
        
        if (isEqual && prov.getCountry() == null )
        	return this.getCountry() == null;
        else if (isEqual && !prov.getCountry().equals( this.getCountry() ) ) 
        	return false;
        else if (!isEqual)
        	return false;

        return true;
    }

	/**
	 * Implementation of the hashCode method provided by the serializable interface.
	 */
    public int hashCode() {
        int result;
        if (this == null || this.getName() == null || this.getCountry() == null)
        	result = 0;
        else
        	result = this.getName().hashCode() + this.getCountry().hashCode();
        return result;
    }
    
	/**
	 * Implementation of the toString() method to show the data of the StateOT
	 * formatted.
	 */
	public String toString() {
		StringBuffer result = new StringBuffer();
		try {
			result.append("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
			result.append("\nID: ");
			result.append(this.idState);
			result.append("\nNAME: ");
			result.append(this.name);
			result.append("\nCOUNTRY: ");
			result.append(this.country != null?this.country.getInternalValue():"NULL");
			
			result.append("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
		}
		catch (Exception ex) {
			System.out.println("Error formatting StateOT!");
			ex.printStackTrace();
			return null;
		}
		
		return result.toString();
	}
	
	@Override
	public boolean equals(Long id) {
		return id != null && this.idState == id.longValue();
	}
	
	@Override
	public long getInternalId() {
		return this.idState;
	}

	@Override
	public String getInternalValue() {
		return this.name;
	}
	
	@Override
	public String getEntityId() {
		return InterfaceExplica.EXPLICA_ENTITY_STATE_ID;
	}
	
	
	
	

}
